﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
namespace gamexpert.admin
{
    public partial class Members : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!(User.Identity.IsAuthenticated && User.IsInRole("Administrator")))
            {
                Response.Redirect("~/admin/Default.aspx");
            }
            LinkButton lb = (LinkButton)Master.FindControl("lbtn_members");
            lb.CssClass = "selected";

            //DataSet1 ds = new DataSet1();
            //DataSet1TableAdapters.vw_aspnet_MembershipUsersTableAdapter da = new DataSet1TableAdapters.vw_aspnet_MembershipUsersTableAdapter();
            ////DataSet1TableAdapters.vw_aspnet_UsersTableAdapter da = new DataSet1TableAdapters.vw_aspnet_UsersTableAdapter();
            ////da.Fill(ds.vw_aspnet_Users);
            //da.Fill(ds.vw_aspnet_MembershipUsers);
            //GridView1.DataSource = ds;
            //GridView1.DataMember = "vw_aspnet_MembershipUsers";
            ////GridView1.DataMember = "vw_aspnet_Users";
            //GridView1.AllowPaging = true;
            ////GridView1.AllowSorting = true;
            //GridView1.AutoGenerateSelectButton = true;
            //GridView1.DataBind();
            
            //GridView1.AutoGenerateEditButton = true;
            //GridView1.AutoGenerateDeleteButton = true;
            MultiView1.ActiveViewIndex = 0;
        }

        protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
        {
            
        }

        protected void LinkButton1_Click(object sender, EventArgs e)
        {
            //DataTable toExcel = formattedDataTable.Copy();
            DataSet1 ds = new DataSet1();
            //DataSet1TableAdapters.my_enquiryTableAdapter da = new DataSet1TableAdapters.my_enquiryTableAdapter();
            //DataSet1TableAdapters.aspnet_Users1TableAdapter da = new DataSet1TableAdapters.aspnet_Users1TableAdapter();
            DataSet1TableAdapters.vw_aspnet_MembershipUsersTableAdapter da = new DataSet1TableAdapters.vw_aspnet_MembershipUsersTableAdapter();
            da.Fill(ds.vw_aspnet_MembershipUsers);
            DataTable toExcel = ds.vw_aspnet_MembershipUsers;
            HttpContext context = HttpContext.Current;
            context.Response.Clear();

            foreach (DataColumn column in toExcel.Columns)
            {
                context.Response.Write(column.ColumnName + ",");
            }

            context.Response.Write(Environment.NewLine);
            foreach (DataRow row in toExcel.Rows)
            {
                for (int i = 0; i < toExcel.Columns.Count; i++)
                {
                    context.Response.Write(row[i].ToString().Replace(",", string.Empty) + ",");
                }

                context.Response.Write(Environment.NewLine);
            }

            context.Response.ContentType = "text/csv";
            context.Response.AppendHeader("Content-Disposition", "attachment; filename=Members_" + DateTime.Now.ToShortDateString() + ".csv");
            context.Response.End();
        }

        
    }
}
